import re
from utils import String_Util


def single_verify(func):
    """
    数据单向校验字段注解装饰器
    """

    def wrapper(self, verify):
        if "varchar" in self.sql_type:
            length = re.findall(r"\d+", self.sql_type)[0]
            code_length = f""", length = {length}"""
        else:
            code_length = ""
        if verify:
            return f"""@SingleVerification(name = "{self.comment}"{code_length})
    {func(self, verify)}"""
        else:
            return func(self, verify)

    return wrapper
